// number of times to attempt a transfer before giving up
#define ATTEMPT_MAX 2
+// seconds to wait for expected message, this value is 1 greater than
+// minimum, i.e. READ_TIMEOUT - 1 <= actual_timeout <= READ_TIMEOUT
+#define READ_TIMEOUT 6
// debug output: low, medium, high, higher
#define DBGLVL_L 1
gettimeofday(&tv, NULL);
debug_out("%u.%03u %s", (unsigned)tv.tv_sec & 0xf, (unsigned)tv.tv_usec / 1000, s);
#else
- debug_out("%s", s);
+ debug_out("%u %s", (unsigned)time(NULL) & 0xf, s);
#endif
}
}
static void
-packet_write(const void* p, unsigned size)
+packet_write(const void* buf, unsigned size)
{
unsigned n;
if (global_opts.debug_level >= DBGLVL_H) {
unsigned j;
- const gbuint8* pp = p;
+ const gbuint8* p = buf;
debug_out_time("pcktwr");
for (j = 0; j < size; j++) {
- warning(" %02x", pp[j]);
+ warning(" %02x", p[j]);
}
if (global_opts.debug_level >= DBGLVL_H2) {
warning(" ");
for (j = 0; j < size; j++) {
- int c = pp[j];
+ int c = p[j];
warning("%c", isprint(c) ? c : '.');
}
}
warning("\n");
}
- n = delbin_os_ops.packet_write(p, size);
+ n = delbin_os_ops.packet_write(buf, size);
if (n != size) {
fatal(MYNAME ": short write %u %u\n", size, n);
}
}
// Get specific message, ignoring others. Sends ACK for non-interval messages.
-// Gives up if 6 navigation messages are received, which means we waited at least
-// 5 seconds.
+// Gives up after at least READ_TIMEOUT-1 seconds have passed.
static int
message_read(unsigned msg_id, message_t* m)
{
unsigned id;
- int interval_message_count = 0;
+ time_t time_start = time(NULL);
if (global_opts.debug_level >= DBGLVL_M)
warning(MYNAME ": looking for %x\n", msg_id);
break;
}
message_ack(id, m);
- if (id == msg_id) {
+ if (id == msg_id || time(NULL) - time_start >= READ_TIMEOUT) {
break;
}
- if (id == MSG_NAVIGATION) {
- interval_message_count++;
- if (interval_message_count == 6) {
- break;
- }
- }
}
return id == msg_id;
}
if (global_opts.debug_level >= DBGLVL_M)
warning(MYNAME ": begin get_batch\n");
do {
- unsigned timeout_count = 0;
+ time_t time_start = time(NULL);
if (i == array_max) {
message_t* old_a = a;
array_max += array_max;
id = message_read_1(0, &a[i]);
switch (id) {
case MSG_NAVIGATION:
- timeout_count++;
- if (timeout_count == 6) {
+ if (time(NULL) - time_start >= READ_TIMEOUT) {
success = 0;
break;
}
// fall through
- case 0:
case MSG_ACK:
case MSG_NACK:
case MSG_SATELLITE_INFO:
warning(MYNAME ": begin send_batch, %u messages\n", n);
for (i = 0; i < n; i++) {
unsigned timeout_count = 0;
+ time_t time_start = time(NULL);
+
message_write(batch_array[i].msg_id, &batch_array[i].msg);
for (;;) {
unsigned id = message_read_1(0, &m);
case MSG_ACK:
break;
case MSG_NAVIGATION:
- timeout_count++;
- if (timeout_count > 2) {
- fatal(MYNAME ": send_batch timed out\n");
- }
- if (timeout_count == 2) {
+ if (time(NULL) - time_start >= 2) {
+ if (timeout_count) {
+ fatal(MYNAME ": send_batch timed out\n");
+ }
+ timeout_count++;
if (global_opts.debug_level >= DBGLVL_M)
warning(MYNAME ": re-sending %x\n", batch_array[i].msg_id);
message_write(batch_array[i].msg_id, &batch_array[i].msg);
+ time_start = time(NULL);
}
// fall through
- case 0:
case MSG_NACK:
case MSG_SATELLITE_INFO:
continue;
case gt_benchmark: gc_sym = 172; break;
case gt_cito: gc_sym = 167; break;
case gt_mega: gc_sym = 166; break;
+ case gt_wherigo: gc_sym = 164; break;
case gt_unknown:
case gt_locationless:
case gt_ape:
{
int i;
for (i = 0; i < n_delbin_units; i++) {
- printf("%d %s %s\n",
+ printf("%u %s %s\n",
delbin_unit_info[i].unit_number,
delbin_unit_info[i].unit_serial_number,
delbin_unit_info[i].unit_name );